using System.Collections.Generic;
using UnityEngine;

public class GameplayEventsManager : MonoBehaviour
{
	public static GameplayEventsManager instance;

	public List<ITimedEvent> allTimedEvents;

	public List<KillInfo> killsList;

	public List<VehicleDestroyInfo> vehicleDestroyList;

	public List<VehicleStealInfo> vehicleStealList;

	public List<DrivingEventInfo> jumpList;

	[Header("Profile Counters")]
	public int destroyedOnlineCars;

	public int destroyedOnlineTanks;

	public int destroyedOnlineHelicopters;

	public int destroyedOnlineBoats;

	public int destroyedOnlineBikes;

	private void Awake()
	{
		instance = this;
		allTimedEvents = new List<ITimedEvent>();
		killsList = new List<KillInfo>();
		vehicleStealList = new List<VehicleStealInfo>();
		vehicleDestroyList = new List<VehicleDestroyInfo>();
		jumpList = new List<DrivingEventInfo>();
	}

	private void Start()
	{
		Reset(true);
	}

	public void SaveAndReset(bool resetPoints)
	{
		SaveConters();
		Reset(resetPoints);
		PlayerPrefs.Save();
	}

	public void SaveConters()
	{
		SaveCounter(destroyedOnlineCars, settings.keyDestroyedOnlineCars);
		destroyedOnlineCars = 0;
		SaveCounter(destroyedOnlineTanks, settings.keyDestroyedOnlineTanks);
		destroyedOnlineTanks = 0;
		SaveCounter(destroyedOnlineHelicopters, settings.keyDestroyedOnlineHelicopters);
		destroyedOnlineHelicopters = 0;
		SaveCounter(destroyedOnlineBoats, settings.keyDestroyedOnlineBoats);
		destroyedOnlineBoats = 0;
		SaveCounter(destroyedOnlineBikes, settings.keyDestroyedOnlineBikes);
		destroyedOnlineBikes = 0;
	}

	public void SaveCounter(int counter, string counterId)
	{
		int num = BCWStorage.Get<int>(counterId);
		num += counter;
		BCWStorage.Set(counterId, num);
	}

	public void Reset(bool resetPoints)
	{
		killsList.Clear();
		vehicleDestroyList.Clear();
		vehicleStealList.Clear();
		jumpList.Clear();
		foreach (ITimedEvent allTimedEvent in allTimedEvents)
		{
			allTimedEvent.Reset();
		}
		allTimedEvents.Clear();
		GameplayRewardManager.instance.Reset(resetPoints);
	}

	public void NewOnlineKill(WeaponType weaponType, WeaponTypeSpecific weaponTypeSpecific, float distance, int playerID, float timeOfRespawn, bool headshot, bool invisible, bool victemJetpack, bool killerJetpack, bool isCating, bool sniperMod)
	{
		KillInfo killInfo = new KillInfo(weaponType, weaponTypeSpecific, distance, playerID, timeOfRespawn, headshot, invisible, victemJetpack, killerJetpack, isCating, sniperMod, true, GPE_EnemyType.Player);
		AllKillEvents.instance.CheckAllEvents(killInfo, killsList);
		killsList.Add(killInfo);
		AllKillAchievements.instanse.CheckAllAchivments(killInfo);
		AllUnitaryAchievements.instance.killOnlinePlayers_100.Increment();
		AllUnitaryAchievements.instance.killOnlinePlayers_1000.Increment();
	}

	public void NewOfflineKill(EnemyState currentState, BehaviorModel behaviorModel, EnemyType enemyType, KillInfo killInfo)
	{
		AllKillAchievements.instanse.CheckAllAchivments(killInfo);
		AllUnitaryAchievements.instance.killMobs_1000.Increment();
		GPE_EnemyType enemyType2 = GPE_EnemyType.Non;
		switch (behaviorModel)
		{
		case BehaviorModel.Police:
			SaveCounter(1, settings.keyKilldOfflineCops);
			AllUnitaryAchievements.instance.killMobsPolice_50.Increment();
			enemyType2 = GPE_EnemyType.Police;
			break;
		case BehaviorModel.Civilian:
			SaveCounter(1, settings.keyKilldOfflineCitizens);
			enemyType2 = GPE_EnemyType.Civilian;
			break;
		case BehaviorModel.Passive:
			if (currentState == EnemyState.Aggressive || currentState == EnemyState.Chasing)
			{
				enemyType2 = GPE_EnemyType.Aggressive;
				if (enemyType != EnemyType.Zombie)
				{
					SaveCounter(1, settings.keyKilldOfflineBandits);
					AllUnitaryAchievements.instance.killMobsBandits_50.Increment();
				}
				else
				{
					SaveCounter(1, settings.keyKilldOfflineZombies);
					AllUnitaryAchievements.instance.killMobsZombies_150.Increment();
				}
			}
			else
			{
				SaveCounter(1, settings.keyKilldOfflineCitizens);
			}
			break;
		case BehaviorModel.Aggressive:
			if (enemyType == EnemyType.Zombie)
			{
				SaveCounter(1, settings.keyKilldOfflineZombies);
				AllUnitaryAchievements.instance.killMobsZombies_150.Increment();
			}
			break;
		}
		KillInfo killInfo2 = new KillInfo(killInfo.weaponType, killInfo.weaponTypeSpecific, killInfo.distance, killInfo.playerID, killInfo.timeOfRespawn, killInfo.headshot, killInfo.invisible, false, killInfo.killerJetpack, false, killInfo.sniperMod, false, enemyType2);
		AllKillEvents.instance.CheckAllEvents(killInfo2, killsList);
		killsList.Add(killInfo2);
	}

	public void NewOnlineVehicleDestroy_WithPlayer(WeaponType carType, KillInfo destroyInfo, float distance, bool privateCar)
	{
		AllDestroyAchievements.instanse.CheckAllAchivments(destroyInfo, carType);
		bool isTank = false;
		if (carType == WeaponType.Tank)
		{
			isTank = true;
		}
		VehicleDestroyInfo vehicleDestroyInfo = new VehicleDestroyInfo(destroyInfo.weaponType, distance, privateCar, isTank);
		AllVehicleDestroyEvents.instance.CheckAllEvents(vehicleDestroyInfo, vehicleDestroyList);
		vehicleDestroyList.Add(vehicleDestroyInfo);
	}

	public void NewVehicleStealEvent(VehicleType vehicleType)
	{
		VehicleStealInfo vehicleStealInfo = new VehicleStealInfo(vehicleType);
		AllVehicleStealEvents.instance.CheckAllEvents(vehicleStealInfo, vehicleStealList);
		vehicleStealList.Add(vehicleStealInfo);
	}

	public void NewDrivingEvent(float distance, CarBehavior vehicle, bool loop)
	{
		DrivingEventInfo drivingEventInfo = new DrivingEventInfo(distance, vehicle, loop);
		AllDrivingEvents.instance.CheckAllEvents(drivingEventInfo, jumpList);
		if (!loop)
		{
			jumpList.Add(drivingEventInfo);
		}
	}

	public void NewOnlineVehicleDestroy(WeaponType carType, KillInfo destroyInfo)
	{
		switch (carType)
		{
		case WeaponType.Car:
			destroyedOnlineCars++;
			break;
		case WeaponType.Tank:
			destroyedOnlineTanks++;
			break;
		case WeaponType.Helicopter:
			destroyedOnlineHelicopters++;
			break;
		case WeaponType.Boat:
			destroyedOnlineBoats++;
			break;
		case WeaponType.Bike:
			destroyedOnlineBikes++;
			break;
		}
	}

	public void NewOfflineVehicleDestroy(WeaponType carType, KillInfo destroyInfo)
	{
		switch (carType)
		{
		case WeaponType.Car:
			SaveCounter(1, settings.keyDestroyedOfflineCars);
			break;
		case WeaponType.Tank:
			SaveCounter(1, settings.keyDestroyedOfflineTanks);
			break;
		case WeaponType.Helicopter:
			SaveCounter(1, settings.keyDestroyedOfflineHelicopters);
			break;
		case WeaponType.Boat:
			SaveCounter(1, settings.keyDestroyedOfflineBoats);
			break;
		case WeaponType.Bike:
			SaveCounter(1, settings.keyDestroyedOfflineBikes);
			break;
		}
	}
}
